package com.xjh.him.controller.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xjh.tool.common.ErrorMsg;
import org.xjh.tool.vo.AjaxResultVO;

@Slf4j
@ControllerAdvice
public class ControllerExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public AjaxResultVO handle(Exception e) {
        StringBuilder builder = new StringBuilder();
        for (StackTraceElement element : e.getStackTrace()) {
            builder.append(element.toString()).append(System.lineSeparator());
        }
        log.error("{}: {}", builder, e.getMessage());
        return AjaxResultVO.getFailureResult(ErrorMsg.ERR_SYSTEM_BUSY);
    }
}
